package com.smt.ejb3;

import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Stateless
@Remote
public class PersonManagerBean implements PersonManager {

	
	@PersistenceContext(unitName = "ejb3db1")
	private EntityManager em1;
	
	@PersistenceContext(unitName = "ejb3db2")
	private EntityManager em2;
	
	@Override
	public void saveMan(Man m) {
		em1.persist(m);
	}

	@Override
	public void saveWoman(Woman w) {
		em2.persist(w);
	}

	@Override
	public void saveAndThrowException() {
		Man m = new Man();
		m.setName("not man");
		Woman w = new Woman();
		w.setName("not woman");
		em2.persist(w);
		em1.persist(m);
		throw new RuntimeException("Any Exception");
	}

}
